package cn.lqz.bucttrain.mapper;

import cn.lqz.bucttrain.annotations.AutoFill;
import cn.lqz.bucttrain.enums.OperationTypeEnum;
import cn.lqz.bucttrain.pojo.dto.PassengerPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Passenger;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface PassengerMapper {

    @Select("select * from passenger where passenger_id=#{passengerId}")
    Passenger findByPassengerId(Long passengerId);

    /**
     * 批量查找
     * @param passengerPageQueryDTO
     * @return
     */
    Page<Passenger> findBatch(PassengerPageQueryDTO passengerPageQueryDTO);

    /**
     * 修改
     * @param passenger
     */
    @AutoFill(OperationTypeEnum.UPDATE)
    void update(Passenger passenger);

    /**
     * 新增
     * @param passenger
     */
    @AutoFill(OperationTypeEnum.INSERT)
    void insert(Passenger passenger);

    /**
     * 删除
     * @param passengerId
     */
    @Delete("delete from passenger where passenger_id = #{passengerId}")
    void delete(Long passengerId);

    /**
     * 根据userId查询该用户绑定的所有乘客
     * @param userId
     * @return
     */
    @Select("select * from passenger where user_id=#{userId}")
    List<Passenger> findBatchByUserId(Long userId);

    /**
     * 查询
     * @param phoneNumber
     * @param userId
     * @return
     */
    @Select("select * from passenger where phone_number=#{phoneNumber} and user_id=#{userId}")
    Passenger findByPhoneNumberAndUserId(String phoneNumber,Long userId);

    /**
     * 删除用户所关联的所有乘客
     * @param userId
     */
    @Delete("delete from passenger where user_id=#{userId}")
    void deleteByUserId(Long userId);
}
